-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Create radial_basis_function_neural_network #12342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…neural_network.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
import numpy as np # For numerical operations | ||
|
||
class RBFNN: | ||
def __init__(self, input_size, hidden_size, output_size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: input_size
Please provide type hint for the parameter: hidden_size
Please provide type hint for the parameter: output_size
# Initialize weights for the output layer | ||
self.weights = np.random.rand(hidden_size, output_size) # Weights for output layer | ||
|
||
def rbf(self, x, center, spread): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function rbf
Please provide return type hint for the function: rbf
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide type hint for the parameter: center
Please provide type hint for the parameter: spread
""" Radial Basis Function (Gaussian). """ | ||
return np.exp(-np.linalg.norm(x - center) ** 2 / (2 * spread ** 2)) | ||
|
||
def forward(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function forward
Please provide return type hint for the function: forward
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
output = np.dot(hidden_outputs, self.weights) # Compute final output | ||
return output | ||
|
||
def train(self, X, y, epochs, learning_rate): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function train
Please provide return type hint for the function: train
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: X
Please provide type hint for the parameter: X
Please provide descriptive name for the parameter: y
Please provide type hint for the parameter: y
Please provide type hint for the parameter: epochs
Please provide type hint for the parameter: learning_rate
# Update weights | ||
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error | ||
|
||
def predict(self, X): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function predict
Please provide return type hint for the function: predict
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: X
Please provide type hint for the parameter: X
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
import numpy as np # For numerical operations | ||
|
||
class RBFNN: | ||
def __init__(self, input_size, hidden_size, output_size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: input_size
Please provide type hint for the parameter: hidden_size
Please provide type hint for the parameter: output_size
# Initialize weights for the output layer | ||
self.weights = rng.random((hidden_size, output_size)) # Weights for output layer | ||
|
||
def rbf(self, x, center, spread): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function rbf
Please provide return type hint for the function: rbf
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide type hint for the parameter: center
Please provide type hint for the parameter: spread
""" Radial Basis Function (Gaussian). """ | ||
return np.exp(-np.linalg.norm(x - center) ** 2 / (2 * spread ** 2)) | ||
|
||
def forward(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function forward
Please provide return type hint for the function: forward
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
output = np.dot(hidden_outputs, self.weights) # Compute final output | ||
return output | ||
|
||
def train(self, x_train, y_train, epochs, learning_rate): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function train
Please provide return type hint for the function: train
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x_train
Please provide type hint for the parameter: y_train
Please provide type hint for the parameter: epochs
Please provide type hint for the parameter: learning_rate
# Update weights | ||
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error | ||
|
||
def predict(self, x_test): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function predict
Please provide return type hint for the function: predict
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x_test
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
import numpy as np | ||
|
||
class ART1: | ||
def __init__(self, num_features, vigilance=0.8): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: num_features
Please provide type hint for the parameter: vigilance
self.vigilance = vigilance | ||
self.weights = [] # Stores the weights for clusters | ||
|
||
def _similarity(self, x, w): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function _similarity
Please provide return type hint for the function: _similarity
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: w
Please provide type hint for the parameter: w
""" | ||
return np.sum(np.minimum(x, w)) / np.sum(x) | ||
|
||
def _weight_update(self, x, w): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function _weight_update
Please provide return type hint for the function: _weight_update
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: w
Please provide type hint for the parameter: w
""" | ||
return np.minimum(x, w) | ||
|
||
def train(self, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function train
Please provide return type hint for the function: train
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: data
if not assigned: | ||
self.weights.append(x.copy()) | ||
|
||
def predict(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function predict
Please provide return type hint for the function: predict
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
||
|
||
class RBFNN: | ||
def __init__(self, input_size, hidden_size, output_size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: input_size
Please provide type hint for the parameter: hidden_size
Please provide type hint for the parameter: output_size
(hidden_size, output_size) | ||
) # Weights for output layer | ||
|
||
def rbf(self, x, center, spread): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function rbf
Please provide return type hint for the function: rbf
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide type hint for the parameter: center
Please provide type hint for the parameter: spread
"""Radial Basis Function (Gaussian).""" | ||
return np.exp(-(np.linalg.norm(x - center) ** 2) / (2 * spread**2)) | ||
|
||
def forward(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function forward
Please provide return type hint for the function: forward
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
output = np.dot(hidden_outputs, self.weights) # Compute final output | ||
return output | ||
|
||
def train(self, x_train, y_train, epochs, learning_rate): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function train
Please provide return type hint for the function: train
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x_train
Please provide type hint for the parameter: y_train
Please provide type hint for the parameter: epochs
Please provide type hint for the parameter: learning_rate
# Update weights | ||
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error | ||
|
||
def predict(self, x_test): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function predict
Please provide return type hint for the function: predict
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x_test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
import numpy as np | ||
|
||
class ART1: | ||
def __init__(self, num_features, vigilance=0.8): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: num_features
Please provide type hint for the parameter: vigilance
self.vigilance = vigilance | ||
self.weights = [] # Stores the weights for clusters | ||
|
||
def _similarity(self, x, w): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function _similarity
Please provide return type hint for the function: _similarity
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: w
Please provide type hint for the parameter: w
""" | ||
return np.sum(np.minimum(x, w)) / np.sum(x) | ||
|
||
def _weight_update(self, x, w): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function _weight_update
Please provide return type hint for the function: _weight_update
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: w
Please provide type hint for the parameter: w
""" | ||
return np.minimum(x, w) | ||
|
||
def train(self, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function train
Please provide return type hint for the function: train
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: data
if not assigned: | ||
self.weights.append(x.copy()) | ||
|
||
def predict(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py
, please provide doctest for the function predict
Please provide return type hint for the function: predict
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
||
|
||
class RBFNN: | ||
def __init__(self, input_size, hidden_size, output_size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: input_size
Please provide type hint for the parameter: hidden_size
Please provide type hint for the parameter: output_size
(hidden_size, output_size) | ||
) # Weights for output layer | ||
|
||
def rbf(self, x, center, spread): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function rbf
Please provide return type hint for the function: rbf
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Please provide type hint for the parameter: center
Please provide type hint for the parameter: spread
"""Radial Basis Function (Gaussian).""" | ||
return np.exp(-(np.linalg.norm(x - center) ** 2) / (2 * spread**2)) | ||
|
||
def forward(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function forward
Please provide return type hint for the function: forward
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
output = np.dot(hidden_outputs, self.weights) # Compute final output | ||
return output | ||
|
||
def train(self, x_train, y_train, epochs, learning_rate): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function train
Please provide return type hint for the function: train
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x_train
Please provide type hint for the parameter: y_train
Please provide type hint for the parameter: epochs
Please provide type hint for the parameter: learning_rate
# Update weights | ||
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error | ||
|
||
def predict(self, x_test): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py
, please provide doctest for the function predict
Please provide return type hint for the function: predict
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x_test
for more information, see https://pre-commit.ci
Closing require_type_hints PRs to prepare for Hacktoberfest |
Implemented the Radial Basis Function Neural Network inside the neural_network folder of the repo. Feel free to tell if it require any changes.